/////////////////////////////////////////////
// ObjectARX defined commands

#include "StdAfx.h"
#include "StdArx.h"


// This is command 'RBCIRC'
void rbcirc()
{
	ads_point cp = {5.0, 5.0, 0.0};
	ads_real rad = 2.24086;
	ads_name circEnt;
	int rc = RTNORM;
	char kw[4];
	struct resbuf *rbcirc;

	acedCommand(RTSTR, "CIRCLE",
				RTPOINT, cp,
				RTREAL, rad,
				RTNONE);

	rc = acdbEntLast(circEnt);
	if(rc == RTNORM)
	{
		if(!printEntInfo(circEnt))
		{
			acutPrintf("\nFailed to print entity info. ");
			return;
		}
	}
	else
	{
		acutPrintf("\nFailed to retrieve last entity. ");
		return;
	}

	while(rc == RTNORM)
	{
		acedInitGet(NULL, "Yes No");
		rc = acedGetKword("\nDraw another circle [Yes/No]<Yes>: ", kw);

		switch(rc)
		{
			case RTERROR:
				acutPrintf("\nAn input error occured - aborting. ");
				return;
			break;

			case RTCAN:
				acutPrintf("\nUser pressed the [ESC] key. ");
				return;
			break;

			case RTNONE:
				strcpy(kw, "Yes");
				rc = RTNORM;
			break;
		} // switch

		if(strcmp(kw, "No") == 0)
		{
			rc = RTNONE;
		}
		else
		{
			acedInitGet(RSG_NONULL, NULL);
			rc = acedGetPoint(NULL, "\nPick circle center point: ", cp);
			if(rc != RTNORM)
			{
				acutPrintf("\nError picking circle center point: ");
				break;
			}

			acedInitGet(RSG_NONULL + RSG_NOZERO + RSG_NONEG, NULL);
			rc = acedGetDist(cp, "\nCircle radius: ", &rad);
			if(rc != RTNORM)
			{
				acutPrintf("\nError entering circle radius: ");
				break;
			}

			rbcirc = acutBuildList(RTSTR, "CIRCLE",
								   RTPOINT, cp,
								   RTREAL, rad,
								   RTNONE);

			if(!rbcirc)
			{
				acutPrintf("\nError with acutBuildList(): ");
				break;
			}

			rc = acedCmd(rbcirc);
			if(rc != RTNORM)
			{
				acutPrintf("\nError creating circle with acedCmd(): ");
				acutRelRb(rbcirc);
				break;
			}

			rc = acdbEntLast(circEnt);
			if(rc != RTNORM)
			{
				acutPrintf("\nFailed to retrieve last entity. ");
				acutRelRb(rbcirc);
				break;
			}

			if(!printEntInfo(circEnt))
			{
				acutPrintf("\nFailed to print last circle's data. ");
			}

			acutRelRb(rbcirc);

		} // else

	} // while
}

